package com.scrumtrek.trainings.tdd;

import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * User: skashin
 * Date: 20.02.13
 * Time: 15:33
 * To change this template use File | Settings | File Templates.
 */
public class Db {

    private static Db db = null;

    private static Set<Item> items = new HashSet<Item>();
    private static Set<Author> authors = new HashSet<Author>();

    public static Db getInstance(){
         if(db==null){
           db = new Db();
         }
         return db;
    }

    public Set<Item> getItems() {
        return items;
    }

    public Set<Author> getAuthors() {
        return authors;
    }

    public void addItem(Item item) {
        items.add(item);
    }


    public Author findAuthorByName(String authorName) {
        if(authorName==null){
            return null;
        }

        for(Author author:authors){
             if(authorName.equalsIgnoreCase(author.getName())){
                 return author;
             }
        }
        return null;
    }
}
